<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>修改挂号信息界面</title>  
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">
  </head>

  <script src="<%=path %>/plugins/layui/layui.js"></script>
  
  <body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>请君慎重修改</legend>
</fieldset>
<form class="layui-form layui-form-pane" id="MedicineForm" lay-filter="example" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">药品名称</label>
    <div class="layui-input-inline">
      <input type="hidden" id="medId" name="medId" value="${medicine.medId }"/>
      <input style="width:500px;" type="text" name="medName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">服用方式</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="medSpec" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">药瓶规格</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="medCount" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">药品作用</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="medFuntion" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">药品价格</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="medPrice" lay-verify="medPrice" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">保质期</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text"  name="medTime" lay-verify="medTime" placeholder="几个月" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
    <div class="layui-inline" 
	     style="font-size: 15px;margin-top: 8px;font-weight: bold;">个月
	 </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">生产地址</label>
    <div class="layui-input-inline">
      <input style="width:500px;" type="text" name="medAddress" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">药品类型</label>
    <div class="layui-input-block">
      <select name="medType" lay-filter="medType" lay-verify="required">
        <option value=""></option>
        <option value="处方药" selected="">处方药</option>
        <option value="非处方药" >非处方药</option>
      </select>
    </div>
  </div>


  <div class="layui-form-item" align="center">
    <button class="layui-btn" lay-submit="" lay-filter="submit">更新信息</button>
  </div>
  </form>
</body>
  
<script>
layui.use(['form', 'layedit', 'laydate', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,$ = layui.jquery;

  //日期
  laydate.render({
    elem: '#test1'
    });
  
//自定义验证规则
    form.verify({
    medPrice: [/^(0|([1-9]\d{0,9}(\.\d{1,2})?))$/, '请输入正确的价格格式！']
    ,medTime: [/\b\d{3}\b/, '请输入两位有效数字！']
  }); 
  
  //监听提交
  form.on('submit(submit)', function(data){
	$.ajax({
		url: '<%=path%>/biz/Medicine_update.action',
		type: 'POST',
		data: $('#MedicineForm').serialize(),
		dataType: 'json',
		success: function(data){
			var json = eval("("+data+")");
			//添加成功
			if(json.isSucceed){
				layer.open({
			        content: '<div style="padding: 20px 100px;">修改成功~</div>'
			        ,btn: '朕知道了'
			        ,btnAlign: 'c' //按钮居中
			        ,shade: 0 //不显示遮罩
			        ,yes: function(){
			        	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 
						parent.layer.close(index); //再执行关闭当前iframe页面  
						parent.location.reload();//刷新父页面
			        }
			      });

			}else{
				message("修改失败~不解释");
			}
		},
		error: function(data){
			layer.msg("请求失败");
		}
	});
	return false;
  });  
  
  //表单初始赋值
  form.val('example', {
     "medName": '${medicine.medName}' // "name": "value"
    ,"medSpec": '${medicine.medSpec}'
    ,"medCount": '${medicine.medCount}'
    ,"medFuntion": '${medicine.medFuntion}'
    ,"medPrice": '${medicine.medPrice}'
    ,"medTime": '${medicine.medTime}'
    ,"medAddress": '${medicine.medAddress}'
    ,"medType": '${medicine.medType}'
  });
  
  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
      });
  }

  
  $('#layerDemo .layui-btn').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });
  
});
</script>
</html>
